﻿using System;
using System.Globalization;
using Windows.UI.Xaml.Data;

namespace Smile.Xaml.Converter
{
    /// <summary>Percentage to size.</summary>
    public class PercentageToSize : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, string language)
        {
            double givenValue = 0;
            double max = 500;
            double size = 0;

            // Define maximum
            if (parameter is double)
            {
                max = (double)parameter;
            }
            else if (parameter is string)
            {
                max = System.Convert.ToDouble((string)parameter);
            }

            // Check value
            if (value is double)
            {
                givenValue = (double)value;
            }

            size = givenValue * max / 100;
            size = Math.Round(size);

            return size.ToString();
        }

        public object ConvertBack(object value, Type targetType, object parameter, string language)
        {
            throw new NotImplementedException();
        }
    }
}
